﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebApplicationCultura.Clases;

namespace WebApplicationCultura.Pages.Actividades
{
    public partial class nuevaactividad : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            HttpCookie idEvento = Request.Cookies["idEvento"];
            if (idEvento != null)
            {
                culturaDataContext cdc = new culturaDataContext();
                var evento = from ev in cdc.EVENTOs where (decimal.Parse(idEvento.Value) == ev.ID_EVENTO) select ev;
                this.Label1.Text = evento.First().NOMBRE_EVENTO;
            }
            else
            {
                Response.Redirect("/Pages/error.aspx");
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (Calendar1.Visible == true)
                {
                    this.Button1.Text = "Calendario";
                    this.Calendar1.Visible = false;
                }
                else
                {
                    this.Calendar1.Visible = true;
                    this.Button1.Text = "Ocultar";
                }
            }
            catch (Exception)
            {
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            try
            {
                if (Calendar2.Visible == true)
                {
                    this.Button2.Text = "Calendario";
                    this.Calendar2.Visible = false;
                }
                else
                {
                    this.Calendar2.Visible = true;
                    this.Button2.Text = "Ocultar";
                }
            }
            catch (Exception)
            {
            }
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            try
            {
                culturaDataContext cdc = new culturaDataContext();
                HttpCookie idEvento = Request.Cookies["idEvento"];

                if (idEvento != null)
                {
                    ACTIVIDAD act = new ACTIVIDAD();
                    act.NOMBRE_ACTIVIDAD = this.TextBox1.Text.Trim();
                    act.ID_EVENTO = decimal.Parse(idEvento.Value);
                    act.INICIO_ACTIVIDAD = this.Calendar1.SelectedDate;
                    act.FIN_ACTIVIDAD = this.Calendar2.SelectedDate;
                    act.DESCRIPCION_ACTIVIDAD = this.TextBox4.Text.Trim();
                    cdc.ACTIVIDADs.InsertOnSubmit(act);
                    cdc.SubmitChanges();
                    Response.Redirect("/Pages/Actividades/actividadesevento.aspx");
                }
                else
                {
                    Response.Redirect("/Pages/error.aspx");
                }
            }
            catch (Exception)
            {
                
            }
        }

        protected void Calendar1_SelectionChanged(object sender, EventArgs e)
        {
            try
            {
                this.TextBox2.Text = this.Calendar1.SelectedDate.ToString();
            }
            catch (Exception)
            {
            }
        }

        protected void Calendar2_SelectionChanged(object sender, EventArgs e)
        {
            try
            {
                this.TextBox3.Text = this.Calendar2.SelectedDate.ToString();
            }
            catch (Exception)
            {
            }
        }
    }
}